using System;
using System.Collections.Generic;
using dbvc.data;
using dbvc.Queries;

namespace dbvc.context.Assignment
{
    public class CreateAssignment
    {
        private db_user principal;
        private IList<db_project> projects;
        private IList<db_user> users;

        public CreateAssignment(db_user _principal, db_user user, IList<db_project> projs)
        {
            principal = _principal;
            Assign(new[] {user}, projs);
        }

        public CreateAssignment(db_user _principal, IList<db_user> users, db_project proj)
        {
            principal = _principal;
            Assign(users, new[] {proj});
        }

        public CreateAssignment(db_user _principal, IList<db_user> users, IList<db_project> projs)
        {
            principal = _principal;
            Assign(users, projs);
        }

        public CreateAssignment(db_user _principal, db_user user, db_project proj)
        {
            principal = _principal;
            Assign(new[] {user}, new[] {proj});
        }

        private void Assign(IList<db_user> usrs, IList<db_project> projs)
        {
            projects = projs;
            users = usrs;
        }

        public void Execute()
        {
            foreach (db_project prj in projects)
            {
                foreach (db_user usr in users)
                {
                    GenericQuery<db_user_project>.Create(
                        new db_user_project
                            {
                                id_project = prj.id,
                                id_user = usr.id,
                                assign_date = DateTime.Today
                            });
                }
            }
        }
    }
}